package com.youlu.campus.admin.community.controller;

import com.youlu.campus.common.base.RestResult;
import com.youlu.campus.common.base.RestResultBuilder;
import com.youlu.campus.service.activity.ActivityManualFeedInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@Slf4j
@RestController
public class ActivityManualFeedInfoController {
    @Autowired
    private ActivityManualFeedInfoService activityManualFeedInfoService;

    @PostMapping("/activity/feed-info/pay/import")
    public RestResult importOrderTipss(@RequestParam("file") MultipartFile file,
                                       @RequestParam("activityId") String activityId) {
        try {
            String fileName = file.getOriginalFilename();
            log.info(":>>> 导入订单收款Feed 流:{}", fileName);
            activityManualFeedInfoService.delete(activityId);
            Map<String, Object> res = activityManualFeedInfoService.Import(file.getBytes(), fileName, activityId);
            return RestResultBuilder.builder().success(res).build();
        } catch (Exception e) {
            log.info(":>>> 导入订单收款Feed 流文件错误:{}", e);
            return RestResultBuilder.builder().failure().build();
        }
    }
}
